package ar.com.drinkLabs;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import ar.com.drinkLabs.adapter.ImageAdapter;
import ar.com.drinkLabs.components.ImageCell;

public class PlanningPokerActivity extends Activity {
	private GridView gridView;

	
   @Override
   public void onCreate(Bundle savedInstanceState) {
	   super.onCreate(savedInstanceState);
	   setContentView(R.layout.main);
       gridView = (GridView) findViewById(R.id.gridview_layout);
       gridView.setAdapter(new ImageAdapter(this));

       gridView.setOnItemClickListener(new OnItemClickListener() {
           public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
               
        	   //por ahora pega hardcodeado, levantar de un menu o algo
               PostMethod pm = new PostMethod("http://172.17.193.226:8080/PlanningPokerServer/chichi.dk");
               //tambien, lo debe levantar del input que le de antes el usuario
               pm.addParameter("userName", "seba");
               
               ImageAdapter imageAdapter = (ImageAdapter) gridView.getAdapter();
               ImageCell imageCell = imageAdapter.mThumbIds[position];
               pm.addParameter("cardValue", imageCell.getCardValue());
               
               Toast.makeText(PlanningPokerActivity.this, "Has elegido la carta: " + imageCell.getCardValue(), Toast.LENGTH_LONG).show();
               HttpClient httpClient = new HttpClient();
               try{
            	   httpClient.executeMethod(pm);
				
			} catch (HttpException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
           }
       });

   }

}